package main

import (
	"crypto/md5"
	"fmt"
	"io"
)

func main() {

	// 方式一
	h := md5.New()
	io.WriteString(h, "我爱中国")
	io.WriteString(h, "welcome to china")
	fmt.Printf("%x\n", h.Sum(nil)) // c74c56a3e122699ccbe959b44780723f

	// 错误
	s := []byte("我爱中国welcome to china")
	h2 := md5.New()
	fmt.Printf("%x\n", h2.Sum(s))
	// e68891e788b1e4b8ade59bbd77656c636f6d6520746f206368696e61d41d8cd98f00b204e9800998ecf8427e

	// 方式二
	h3 := md5.New()
	h3.Write(s)
	fmt.Printf("%x\n", h3.Sum(nil)) // c74c56a3e122699ccbe959b44780723f

	// 方式三
	fmt.Printf("%x\n", md5.Sum(s)) // c74c56a3e122699ccbe959b44780723f
}
